import prompt from '@system.prompt';
import http from '@ohos.net.http';
import router from '@system.router';
export default {
    data: {
        title: 'World',
        username: "",
        password: "",
        userTemp: {
            "userName": null, "userPassword": null,
            "userQuestion": null, "userAnswer": null
        },
        msg:""
    },

    login(){
        // 每一个httpRequest对应一个http请求任务，不可复用
        let httpRequest = http.createHttp();

        httpRequest.request(
        // 填写http请求的url地址，可以带参数也可以不带参数。URL地址需要开发者自定义。GET请求的参数可以在extraData中指定
            this.$app.$def.getUserLoginUrl(this.username, this.password),
            {
                method: 'GET',
            }, (err, data) => {
            if (!err) {
                // data.result为http响应内容，可根据业务需要进行解析
                console.info('Result:' + data.result);
                console.log("--------->")
                this.$app.$def.globalData.jsonResult = JSON.parse(data.result);
                this.$app.$def.globalData.user = this.$app.$def.globalData.jsonResult.info;
                console.info('user:' + JSON.stringify(this.$app.$def.globalData.user));
                console.info('code:' + this.$app.$def.globalData.jsonResult);
                console.info('msg:' + this.$app.$def.globalData.jsonResult);
                if(this.$app.$def.globalData.jsonResult.code == 1){
                    router.replace({
                        uri:"pages/index/index"
                    })
                }
                else{
                    this.msg = this.$app.$def.globalData.jsonResult.msg
                    prompt.showToast({
                        message: this.msg,
                        duration: 2000,
                    });

                }
                // data.header为http响应头，可根据业务需要进行解析
                console.info('header:' + data.header);
            } else {
                console.info('error:' + err.data);
            }
        }
        );
    },
    inputUserNameChange(event){
        this.username = event.value;
    },
    inputPasswordChange(event){
        this.password = event.value;
    },
    resetpasswordpage(){
      router.push({
          uri:"pages/resetpassword/resetpassword"
      });
    },

    registerpage(){
        router.push({
            uri:"pages/register/register"
        });
    }
}
